c# generate random date

305

c# generate random date -

 private DateTime GetRandomDate()
 {
   var random = new Random();
   var startDate = DateTime.Now.AddYears(-MaxRange);
   var endDate = DateTime.Now.AddYears(-MinRange);
   var range = Convert.ToInt32(endDate.Subtract(startDate).TotalDays);
   return startDate.AddDays(random.Next(range));
 }

Comments

Submit
0 Comments